﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace ElingOA6_Admin_DSJCJ.BLL
{
    /// <summary>
    /// 用户组BLL
    /// </summary>
    public class PrvGroup
    { /// <summary>
        /// 用户组DAL
        /// </summary>

        private readonly DAL.PrvGroup dal = new DAL.PrvGroup();
        /// <summary>
        /// 构造方法
        /// </summary>
        public PrvGroup()
        { }
        /// <summary>
        /// 获得数据列表
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="strWhere">sql查询语句</param>
        /// <returns>用户组列表</returns>
        public List<Model.PrvGroup> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 根据公司编号获取数据列表
        /// <creator>wangl</creator>
        /// <date>2013-07-29</date>
        /// </summary>
        /// <param name="entityNo">公司编号</param>
        /// <returns>DataSet对象</returns>
        public List<Model.PrvGroup> GetListByEntityNo(string entityNo)
        {
            DataSet ds = dal.GetListByEntityNo(entityNo);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 根据用户组编号获取人员列表
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="groupID">用户组编号</param>
        /// <param name="fentityNo">组织机构代码</param>
        /// <returns>人员列表</returns>
        public List<string> GetLoginIDListByGroupID(string groupID, string fentityNo)
        {
            DAL.PrvGroup prvGroupDAL = new DAL.PrvGroup();
            return prvGroupDAL.GetLoginIDListByGroupID(groupID, fentityNo);
        }

        /// <summary>
        /// 根据用户组编号获取
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="groupID">用户组编号</param>
        /// <param name="fentityNo">组织机构编号</param>
        /// <returns>用户组编号集合</returns>
        public List<string> GetFunctionNOListByGroupID(string groupID, string fentityNo)
        {
            DAL.PrvGroup prvGroupDAL = new DAL.PrvGroup();
            return prvGroupDAL.GetFunctionNOListByGroupID(groupID, fentityNo);
        }

        /// <summary>
        /// 得到一个对象实体
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="fGroupNo">用户组编号</param>
        /// <param name="fEntityNo">组织机构代码</param>
        /// <returns>用户组信息</returns>
        public Model.PrvGroup GetModel(string fGroupNo, string fEntityNo)
        {
            return dal.GetModel(fGroupNo, fEntityNo);
        }

        /// <summary>
        /// 是否存在该记录
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="fGroupNo">用户组编号</param>
        /// <param name="fEntityNo">组织机构代码</param>
        /// <returns>返回是否存额在</returns>
        public bool Exists(string fGroupNo, string fEntityNo)
        {
            return dal.Exists(fGroupNo, fEntityNo);
        }

        /// <summary>
        /// 增加用户组
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="groupModel">用户组信息</param>
        /// <param name="userFuncList">权限信息列表</param>
        /// <param name="orgUserList">用户信息列表</param>
        /// <returns>增加是否成功</returns>
        public string AddPrvGroup(Model.PrvGroup groupModel, List<string> userFuncList, List<string> orgUserList)
        {
            DAL.PrvGroup prvGroupDAL = new DAL.PrvGroup();
            return prvGroupDAL.AddPrvGroup(groupModel, userFuncList, orgUserList);
        }


        /// <summary>
        /// 修改用户组
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="groupModel">用户组信息</param>
        /// <param name="userFuncList">权限信息列表</param>
        /// <param name="orgUserList">用户信息列表</param>
        /// <returns>增加是否成功</returns>
        public void EditPrvGroup(Model.PrvGroup groupModel, List<string> userFuncList, List<string> orgUserList)
        {
            DAL.PrvGroup prvGroupDAL = new DAL.PrvGroup();
            prvGroupDAL.EditPrvGroup(groupModel, userFuncList, orgUserList);
        }


        /// <summary>
        /// 删除用户组
        /// </summary>
        /// <param name="groupID">用户组编号</param>
        /// <param name="fentityNo">组织机构编号</param>
        public void DeleteGroup(string groupID, string fentityNo)
        {
            DAL.PrvGroup prvGroupDAL = new DAL.PrvGroup();
            prvGroupDAL.DeleteGroup(groupID, fentityNo);
        }
        /// <summary>
        /// 根据用户组编号获取人员列表
        /// <creator>wangl</creator>
        /// <date>2012-06-18</date>
        /// </summary>
        /// <param name="groupID"></param>
        /// <returns></returns>
        public List<string> GetLoginIDListByGroupID(decimal groupID)
        {
            DAL.PrvGroup prvGroupDAL = new DAL.PrvGroup();
            return prvGroupDAL.GetLoginIDListByGroupID(groupID);
        }
        /// <summary>
        /// 根据菜单编号获取人员列表
        /// 根据用户组编号获取
        /// <creator>wangl</creator>
        /// <date>2013-11-27</date>
        /// </summary>
        /// <param name="functionNo"></param>
        /// <param name="entityNo"></param>
        /// <returns></returns>
        public List<string> GetLoginIDListByFunctionNo(string functionNo, string entityNo)
        {
            return dal.GetLoginIDListByFunctionNo(functionNo, entityNo);
        }
        /// <summary>
        /// 获取数据列表
        /// <creator>zhongyl</creator>
        /// <date>2013-07-12</date>
        /// </summary>
        /// <param name="dt">需转换数据源信息</param>
        /// <returns>转换后数据列表</returns>
        public List<Model.PrvGroup> DataTableToList(DataTable dt)
        {
            List<Model.PrvGroup> modelList = new List<Model.PrvGroup>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Model.PrvGroup model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Model.PrvGroup();
                    if (dt.Rows[n]["FGroupNo"] != null && dt.Rows[n]["FGroupNo"].ToString() != "")
                    {
                        model.FGroupNo = dt.Rows[n]["FGroupNo"].ToString();
                    }
                    if (dt.Rows[n]["FEntityNo"] != null && dt.Rows[n]["FEntityNo"].ToString() != "")
                    {
                        model.FEntityNo = dt.Rows[n]["FEntityNo"].ToString();
                    }
                    if (dt.Rows[n]["FGroupName"] != null && dt.Rows[n]["FGroupName"].ToString() != "")
                    {
                        model.FGroupName = dt.Rows[n]["FGroupName"].ToString();
                    }
                    if (dt.Rows[n]["FNote"] != null && dt.Rows[n]["FNote"].ToString() != "")
                    {
                        model.FNote = dt.Rows[n]["FNote"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

    }
}
